<?php

namespace app\api\model\message;

use think\Model;


class MessageBoard extends Model
{

    

    

    // 表名
    protected $name = 'message_board';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'source_text'
    ];
    

    
    public function getSourceList()
    {
        return ['10' => __('Source 10'), '20' => __('Source 20'), '30' => __('Source 30')];
    }


    public function getSourceTextAttr($value, $data)
    {
        $value = $value ?: ($data['source'] ?? '');
        $list = $this->getSourceList();
        return $list[$value] ?? '';
    }

    public function getCreatetimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    public function messageType(){
        return $this->hasOne('MessageType','id','message_type_id')->field('id,title');
    }




}
